﻿var picTeacher = {};
picTeacher.operationrow = undefined;
picTeacher.operationtbList = undefined;
picTeacher.dialogObj = {
    title: '选择教师',
    width: 800,
    height: 300,
    closed: false,
    cache: false,
    modal: true,
    iconCls: 'icon-key',
    resizable: true
};
$(function () {
    var name = $("#textSearchTeacher").val();
    picTeacher.para = [{ Field: "IfTeacher", Value: '1', Operator: "=" },{ Field: "UserName", Value: name, Operator: "co" }];
    $("#tbPicTeacher").datagrid({
        url: '/BD/User/GetUserList',
        loadMsg: '数据加载中请稍后……',
        pagination: true,
        rownumbers: true,
        idField: "ID",
        lines: true,
        singleSelect: true,
        pageSize: 10,
        pageList: [10, 20, 30],
        striped: true,
        fitColumns: true,
        queryParams: { searchData: JSON.stringify(picTeacher.para) },
        columns: [[
            { field: 'ck', checkbox: true, width: 30 },
            { field: 'ID', title: 'ID', width: 50, align: "center", hidden: true },
            { field: 'UserCode', title: '教师编号', sortable: true, width: 100, align: "center" },
            { field: 'UserName', title: '教师姓名', sortable: true, width: 100, align: "center" },
            { field: 'SchoolName', title: '校区', sortable: true, width: 80, align: "center" },
            { field: 'DepName', title: '部门', sortable: true, width: 80, align: "center" },
            { field: 'PosName', title: '岗位', sortable: true, width: 80, align: "center" },
            {
                field: 'IfTeacher', title: '是否教师岗', sortable: true, width: 80, align: "center",
                formatter: function (value, row, index) {
                    return com.getArrayText(StaticCombo.YesorNo, value);
                }
            },
            {
                field: 'CourseTypeID', title: '学科', sortable: true, width: 80, align: "center",
                formatter: function (value, row, index) {
                    var CourseType = undefined;
                    com.ajax({
                        url: "/CusIntention/GetCourseTypeName",
                        data: { CourseTypeID: value },
                        async: false,
                        success: function (data) {
                            CourseType = data.CourseType;
                        }
                    });
                    return CourseType;
                }
            },
            { field: 'TLevel', title: '当前等级', sortable: true, width: 80, align: "center" }
        ]]
    });
    $("#pickTeacherDiv").dialog(
        picTeacher.dialogObj
    );
    $("#pickTeacherDiv").dialog("close");
});


picTeacher.ReloadGrid = function () {
    var name = $("#textSearchTeacher").val();
    picTeacher.para = [{ Field: "IfTeacher", Value: '1', Operator: "=" }, { Field: "UserName", Value: name, Operator: "co" }];
    $("#tbPicTeacher").datagrid("reload", {
        SearchData: JSON.stringify(picTeacher.para)
    });
}

picTeacher.Cancel = function () {
    $("#pickTeacherDiv").dialog("close");
}

picTeacher.Confirm = function () {
    var row1 = $("#tbPicTeacher").datagrid("getSelected");
    if (row1) {
        var editors = picTeacher.operationtbList.datagrid('getEditors', picTeacher.operationrowindex);
        $(editors[0].target).combobox('setValue',row1.CourseTypeID);
        $(editors[1].target).val(row1.UserCode);
        $(editors[2].target).val(row1.UserName);
        $(editors[4].target).val(row1.TLevel);

        $("#tbPicTeacher").datagrid("unselectAll");
        $("#pickTeacherDiv").dialog("close");
    }
    else {
        com.message("information", "请选择一条数据");
    }
}

picTeacher.open = function (editRow,tbListObj) {
    picTeacher.operationrowindex = editRow;
    picTeacher.operationtbList = tbListObj;
    $("#pickTeacherDiv").dialog("open");
}